<template>
    <div class="select_class">
        <header >
            <a @click="$api.goBack()" class="back"></a>
            <span>修改密码</span>
        </header>
        <div class="main">
            <div class="flex">
                <div>旧密码</div>
                <div class="red">*</div>
            </div>
            <div><input v-model="detail.oldPwd" type="password" placeholder="请输入旧密码" /></div>
        </div>
        <div class="main">
            <div class="flex">
                <div>新密码</div>
                <div class="red">*</div>
            </div>
            <div><input v-model="detail.newPwd" type="password" placeholder="请输入新密码" /></div>
        </div>
        <div class="main">
            <div class="flex">
                <div>确认新密码</div>
                <div class="red">*</div>
            </div>
            <div><input v-model="detail.newPwd2" type="password" placeholder="请输入新密码" /></div>
        </div>
        <div class="row" style="padding:0.5rem;margin-top:0.6rem;">
            <mt-button style="width:100%;" type="danger" @click="subbmit()">确定</mt-button>
        </div>
    </div>
</template>
<script>
    import {
        MessageBox
    } from 'mint-ui';
    import getImage from '../components/getImage.vue'
    export default {
        data() {
            return {
                useInfo: '',
                detail: {
                    oldPwd: '',
                    newPwd: '',
                    newPwd2: '',
                },
            }
        },
        created() {
            this.getUserInfo();
        },
        methods: {
            getUserInfo() {
                this.useInfo = JSON.parse(sessionStorage.getItem('useInfo'));
            },
            subbmit() { //提交
                var params = JSON.parse(JSON.stringify(this.detail));
                if (params.oldPwd.length == 0) {
                    MessageBox('提示', '旧密码不能为空');
                    return;
                }
                if (params.newPwd.length == 0) {
                    MessageBox('提示', '新密码不能为空');
                    return;
                }
                if (params.newPwd2.length == 0) {
                    MessageBox('提示', '确认新密码不能为空');
                    return;
                }
                if (params.newPwd != params.newPwd2) {
                    MessageBox('提示', '新密码不一致');
                    return;
                }
                var url = "/userInfo/updatePwd"
                this.$api.post(url, params, (data) => {
                    MessageBox('提示', '修改成功');
                    this.$api.goBack();
                })
            }
        }
    }
</script>